package gk.example.adapter;

import gk.example.bean.DateInfo;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.gkdate.R;

public class DateRecordAdapter extends BaseAdapter {
	private Context mContext;
	private List<DateInfo> mDateInfo;

	public DateRecordAdapter(Context context, List<DateInfo> dateInfo) {
		mContext = context;
		mDateInfo = dateInfo;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mDateInfo.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		DateRecordViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new DateRecordViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_date_record, parent, false);

			viewHolder.TvDateRecordTitle = (TextView) convertView
					.findViewById(R.id.tv_record_title);
			viewHolder.TvDateRecordNickName = (TextView) convertView
					.findViewById(R.id.tv_record_nickname);
			viewHolder.TvDateRecordTime = (TextView) convertView
					.findViewById(R.id.tv_record_time);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (DateRecordViewHolder) convertView.getTag();
		}
		viewHolder.TvDateRecordNickName.setText(mDateInfo.get(position)
				.getNickName());
		viewHolder.TvDateRecordTime.setText(mDateInfo.get(position)
				.getDateDate() + " " + mDateInfo.get(position).getDateTime());
		return convertView;
	}

}

class DateRecordViewHolder {
	TextView TvDateRecordTitle;
	TextView TvDateRecordNickName;
	TextView TvDateRecordTime;
}
